import { defineStore } from 'pinia'
import { setStorage,getStorage } from '@/lib/storage'
import { showToast } from '@/lib/showPrompt'

const useCollect = defineStore('collect',{
	state: () => {
		return {
			collectList: getStorage('collect') || []  // 收藏的列表
		}
	},
	actions:{
		// 添加收藏
		addCollect(item){
			this.collectList.push(item) 
			setStorage('collect',this.collectList)
		},
		// 删除收藏的某一项
		deleteCollect(item){
			const index = this.collectList.findIndex(f => f.chat_type === item.chat_type && f.create_time === item.create_time)
			if(index !== -1){
				console.log(1212);
				this.collectList.splice(index,1)
				setStorage('collect',this.collectList)
			}else{
				console.log(999999);
				showToast('删除失败')
			}
		}
	}
})

export default useCollect